"""列表类型配置

包含list类型的C++映射和方法配置
"""

# 列表类型配置
CONFIG = {
    "list[T]": {
        "cpp_type": "mc::array<T>",
        "includes": ["<mc/array.h>"],
        "default_value": "mc::array<T>{{}}",
        "pass_by": "const_ref",  # 容器按常量引用传递
        "generic_params": ["T"],  # 泛型参数
        "iterator_element_type": "T",  # 迭代器元素类型
        "satisfies_protocols": [
            "Iterable",
            "Sequence",
            "Reversible",
            "Sized",
            "Container",
        ],  # 满足的 Protocol
        "methods": {
            "append": {
                "signatures": ["append(self, item: T) -> None"],
                "templates": ["{self}.push_back({item})"],
                "includes": [],
                "priority": 1,
                "mutating": True,
            },
            "extend": {
                "signatures": ["extend(self, iterable: list[T]) -> None"],
                "templates": ["mcpy::list_extend({self}, {iterable})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
                "mutating": True,
            },
            "insert": {
                "signatures": ["insert(self, index: int, item: T) -> None"],
                "templates": ["mcpy::list_insert({self}, {index}, {item})"],
                "includes": ["mcpy/builtins/list.h"],
                "priority": 1,
                "mutating": True,
            },
            "remove": {
                "signatures": ["remove(self, item: T) -> None"],
                "templates": ["mcpy::list_remove({self}, {item})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 0,
                "mutating": True,
            },
            "pop": {
                "signatures": [
                    "pop(self) -> T",
                    "pop(self, index: int) -> T",
                ],
                "templates": [
                    "mcpy::list_pop_back({self})",
                    "mcpy::list_pop({self}, {index})",
                ],
                "includes": ["mcpy/builtins.h"],
                "priority": 0,
                "mutating": True,
            },
            "index": {
                "signatures": [
                    "index(self, item: T) -> int",
                    "index(self, item: T, start: int, end: int) -> int",
                ],
                "templates": [
                    "mcpy::list_index({self}, {item})",
                    "mcpy::list_index({self}, {item}, {start}, {end})",
                ],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
            },
            "count": {
                "signatures": ["count(self, item: T) -> int"],
                "templates": ["mcpy::list_count({self}, {item})"],
                "includes": ["mcpy/builtins/list.h"],
                "priority": 1,
            },
            "sort": {
                "signatures": [
                    "sort(self) -> None",
                    "sort(self, reverse: bool) -> None",
                ],
                "templates": [
                    "std::sort({self}.begin(), {self}.end())",
                    "mcpy::list_sort({self}, {reverse})",
                ],
                "includes": ["<algorithm>", "mcpy/builtins.h"],
                "priority": 0,
                "mutating": True,
            },
            "reverse": {
                "signatures": ["reverse(self) -> None"],
                "templates": ["mcpy::list_reverse({self})"],
                "includes": ["mcpy/builtins/list.h"],
                "priority": 0,
                "mutating": True,
            },
            "clear": {
                "signatures": ["clear(self) -> None"],
                "templates": ["{self}.clear()"],
                "includes": [],
                "priority": 0,
                "mutating": True,
            },
            "size": {
                "signatures": ["size(self) -> int"],
                "templates": ["{self}.size()"],
                "includes": [],
                "priority": 1,
            },
            "__len__": {
                "signatures": ["__len__(self) -> int"],
                "templates": ["{self}.size()"],
                "includes": [],
                "priority": 1,
            },
            "__iter__": {
                "signatures": ["__iter__(self) -> Iterator[T]"],
                "templates": ["mcpy::iter_wrapper({self})"],
                "includes": ["mcpy/builtins/global_functions.h"],
                "priority": 1,
            },
            "__next__": {
                "signatures": ["__next__(self) -> T"],
                "templates": ["{self}.__next__<{T}>()"],
                "includes": ["mcpy/builtins/global_functions.h"],
                "priority": 1,
            },
            "copy": {
                "signatures": ["copy(self) -> list[T]"],
                "templates": ["{self}.copy()"],
                "includes": [],
                "priority": 1,
            },
            "__eq__": {
                "signatures": ["__eq__(self, other: list[T]) -> bool"],
                "templates": ["{self} == {other}"],
                "includes": [],
                "priority": 1,
            },
            "__ne__": {
                "signatures": ["__ne__(self, other: list[T]) -> bool"],
                "templates": ["{self} != {other}"],
                "includes": [],
                "priority": 1,
            },
            "__bool__": {
                "signatures": ["__bool__(self) -> bool"],
                "templates": ["!{self}.empty()"],
                "includes": [],
                "priority": 1,
            },
            "__add__": {
                "signatures": ["__add__(self, other: list[T]) -> list[T]"],
                "templates": ["mcpy::list_concat({self}, {other})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
            },
            "__iadd__": {
                "signatures": ["__iadd__(self, other: list[T]) -> list[T]"],
                "templates": ["mcpy::list_iadd({self}, {other})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
                "mutating": True,
            },
            "__getitem__": {
                "signatures": ["__getitem__(self, index: int) -> T"],
                "templates": ["mcpy::list_getitem({self}, {index})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
            },
            "__setitem__": {
                "signatures": ["__setitem__(self, index: int, value: T) -> None"],
                "templates": ["mcpy::list_setitem({self}, {index}, {value})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
                "mutating": True,
            },
            "__delitem__": {
                "signatures": ["__delitem__(self, index: int) -> None"],
                "templates": ["mcpy::list_delitem({self}, {index})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
                "mutating": True,
            },
            "__contains__": {
                "signatures": ["__contains__(self, item: T) -> bool"],
                "templates": ["mcpy::list_contains({self}, {item})"],
                "includes": ["mcpy/builtins/list.h"],
                "priority": 1,
            },
            "__lt__": {
                "signatures": ["__lt__(self, other: list[T]) -> bool"],
                "templates": ["{self} < {other}"],
                "includes": [],
                "priority": 1,
            },
            "__le__": {
                "signatures": ["__le__(self, other: list[T]) -> bool"],
                "templates": ["{self} <= {other}"],
                "includes": [],
                "priority": 1,
            },
            "__gt__": {
                "signatures": ["__gt__(self, other: list[T]) -> bool"],
                "templates": ["{self} > {other}"],
                "includes": [],
                "priority": 1,
            },
            "__ge__": {
                "signatures": ["__ge__(self, other: list[T]) -> bool"],
                "templates": ["{self} >= {other}"],
                "includes": [],
                "priority": 1,
            },
            "__mul__": {
                "signatures": ["__mul__(self, n: int) -> list[T]"],
                "templates": ["mcpy::list_repeat({self}, {n})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
            },
            "__rmul__": {
                "signatures": ["__rmul__(self, n: int) -> list[T]"],
                "templates": ["mcpy::list_repeat({self}, {n})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
            },
            "__imul__": {
                "signatures": ["__imul__(self, n: int) -> list[T]"],
                "templates": ["mcpy::list_imul({self}, {n})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
                "mutating": True,
            },
            "__repr__": {
                "signatures": ["__repr__(self) -> str"],
                "templates": ["mcpy::list_repr({self})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
            },
            "__str__": {
                "signatures": ["__str__(self) -> str"],
                "templates": ["mcpy::list_repr({self})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
            },
        },
        # 构造函数配置
        "constructors": {
            "signatures": [
                "list() -> list[T]",
                "list(iterable: list[T]) -> list[T]",
                "list(iterable: tuple[T]) -> list[T]",
                "list(iterable: set[T]) -> list[T]",
                "list(iterable: dict_keys[K]) -> list[K]",
                "list(iterable: dict_values[V]) -> list[V]",
                "list(iterable: dict_items[K, V]) -> list[tuple[K, V]]",
            ],
            "templates": [
                "mc::array<T>{}",
                "mcpy::list_construct<{T}>({iterable})",  # 和 set_construct 一样，添加模板参数
                "mcpy::list_construct<{T}>({iterable})",
                "mcpy::list_construct<{T}>({iterable})",
                "mcpy::list_construct<{T}>({iterable})",  # dict_keys[K] -> list[K]，所以 T=K
                "mcpy::list_construct<{T}>({iterable})",  # dict_values[V] -> list[V]，所以 T=V
                "mcpy::list_construct<{T}>({iterable})",  # dict_items[K,V] -> list[tuple[K,V]]，所以 T=tuple[K,V]
            ],
            "includes": ["<mc/array.h>", "mcpy/builtins/list.h"],
            "priority": 1,
        },
    },
    # 无类型注解的列表配置（弱类型）
    "list": {
        "cpp_type": "mc::variants",  # 使用 mc::variants 实现弱类型数组
        "default_constructor_syntax": "braces",  # 使用 {} 构造（默认值，可省略）
        "includes": ["<mc/variant.h>", "mcpy/builtins.h"],
        "default_value": "mc::variants{{}}",
        "is_type": True,
        "module": "builtins",
        # 继承list[T]的所有方法和构造函数，但将T替换为Any（Python类型）
        "inherit_from": "list[T]",
        "type_substitution": {"T": "Any"},
        "satisfies_protocols": [
            "Iterable",
            "Sequence",
            "Reversible",
            "Sized",
            "Container",
        ],  # 满足的 Protocol
    },
    # Python 3.9+ 兼容性：大写类型映射
    "List": {
        "is_type": True,
        "type_alias": "list",
        "module": "typing",
    },
}
